Skip to content

Comments

[Modular] Save Modular Pipeline weights to Hub#13168

Open
DN6 wants to merge 3 commits intomainfrom
modular-save-pretrained-weights
Open

[Modular] Save Modular Pipeline weights to Hub#13168
DN6 wants to merge 3 commits intomainfrom
modular-save-pretrained-weights

Conversation

@DN6
Copy link
Collaborator

@DN6 DN6 commented Feb 20, 2026

What does this PR do?

Enable modular pipelines to save model weights to the Hub. Previously, only configs were saved. Note that if individual components are loaded from external repos, their model configs will continue to reference those repos. I've added an optional overwrite_modular_index flag to rewrite component configs so they point to the destination repo instead.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@DN6 DN6 requested a review from yiyixuxu February 20, 2026 14:02
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@sayakpaul sayakpaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments. Let's also add some simple tests:

  • Checking if the params are being serialized (just checking if the checkpoint files exist is enough)?
  • modular_model_index.json reflects the repository locations properly?

If expressed as an integer, the unit is bytes.
push_to_hub (`bool`, *optional*, defaults to `False`):
Whether to push the pipeline to the Hugging Face model hub after saving it.
**kwargs: Additional keyword arguments passed along to the push to hub method.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we document what is allowed in the kwargs? overwrite_modular_index deserves some documentation IMO.

Comment on lines +1917 to +1918
if component_spec.default_creation_method != "from_pretrained":
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what this is doing?


# Create a new empty model card and eventually tag it
if push_to_hub:
card_content = generate_modular_model_card_content(self.blocks)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this conditioned on the above changes? If not, maybe we can keep it in the earlier position?


save_method(os.path.join(save_directory, component_name), **save_kwargs)

if push_to_hub:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to fully push the push_to_hub path to the end of the implementation as it's easier to follow.

private = kwargs.pop("private", None)
create_pr = kwargs.pop("create_pr", False)
token = kwargs.pop("token", None)
repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this going?

repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1])

for component_name, component_spec in self._component_specs.items():
sub_model = getattr(self, component_name, None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit):

Suggested change
sub_model = getattr(self, component_name, None)
component = getattr(self, component_name, None)

Not all components need to models.

if variant is not None and "variant" in component_spec_dict:
component_spec_dict["variant"] = variant

self.register_to_config(**{component_name: (library, class_name, component_spec_dict)})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too sure about the objective of this block. What happens if its corresponding model_cls doesn't have the save method we support through LOADABLE_CLASSES?

Or is this unrelated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants